package com.ipt.frm.pw;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ipartek.formacion.DAO.DAOFactory;
import com.ipartek.formacion.bean.Alumno;
import com.ipartek.formacion.interfaces.InterfaceAlumnoDAO;

/**
 * Servlet implementation class ServletRanking
 */
public class ServletRanking extends ServletMaestro {

	private static final long serialVersionUID = 1322973748834198634L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ServletRanking() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		ArrayList<Alumno> listaAlumnos = new ArrayList<Alumno>();

		DAOFactory factoria = DAOFactory.getDAOFactory(1);
		InterfaceAlumnoDAO interfaz = factoria.getInterfaceAlumnoDAO();

		try {
			listaAlumnos = interfaz.getRankingGlobal();
		} catch (Exception e) {
			e.printStackTrace();
		}
		request.setAttribute("tablaAlumnos", listaAlumnos);
		RequestDispatcher dispacher = this.getServletContext()
				.getRequestDispatcher("/ranking.jsp");
		dispacher.forward(request, response);

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
